package com.example.chengbangming.chomeapp.net;

import java.io.IOException;
import java.util.Objects;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by carrie on 2017/9/7.
 */

public class OKHttpParams {
    private OkHttpClient okHttpClient;


//    public Object OKHttpParams(String url){
//        Object obj = null;
//        try {
//            okHttpClient = new OkHttpClient();
//            /**
//             * 多个参数
//             */
//
//            FormBody formBody = new FormBody.Builder().
//                    add("name","name").
//                    add("age","3").
//                    add("sex","女").
//                    build();
//
//            Request request = new Request.Builder().
//                    url(url).
//                    addHeader("User-Agent","android").
//                    header("Content-Type","text/html; charset=utf-8;").
//                    post(formBody).
//                    build();
//
//            okHttpClient.newCall(request).enqueue(new Callback() {
//                @Override
//                public void onFailure(Call call, IOException e) {
//                        e.printStackTrace();
//                }
//
//                @Override
//                public void onResponse(Call call, Response response) throws IOException {
//                    //获取响应结果
//                        if(response.isSuccessful()){
//                            String result = response.body().toString();
//                        }
//                }
//            });
//
//            /**
//             * 无参数
//             */
////            Request request = new Request.Builder().
////                    url(url).
////                    get().
////                    build();
////            Response response = okHttpClient.newCall(request).execute();
////            if(!response.isSuccessful()){
////                obj = response;
////            }
////            Headers responseHeaders = response.headers();
////            for(int i = 0;i<responseHeaders.size();i++){
////                System.out.print(responseHeaders.name(i)+"_________"+responseHeaders.value(i));
////            }
////
////            //请求成功返回的结果
////            String resultStr = response.body().string();
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//        return obj;
//    }
}
